<?php
if(!defined('BASEPATH'))
	exit('No direct script access allowed');

class Main extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index() {
		//$this->load->view('welcome_message');

		$this -> load -> model('Torneo_Model');

		$results = $this -> Torneo_Model -> get_tournaments_active();

		$data['tournaments'] = $results;

		$this -> load -> view('league_main', $data);
	}

	public function alterIndex() {
		$this -> load -> view('welcome_message');

	}

	public function match($match_id =FALSE) {

		$this -> load -> model('Torneo_Model');

		if($match_id && is_numeric($match_id)) {

			$results = $this -> Torneo_Model -> get_score_by_match_id($match_id);

			if(sizeof($results) > 0) {

				$data['match_id'] = $results[0] -> match_id;
				$data['match_date'] = $results[0] -> match_date;
				$data['match_scored'] = $results[0] -> match_scored;
				$data['team_home_id'] = $results[0] -> team_home_id;
				$data['team_home_name'] = $results[0] -> team_home_name;
				$data['team_visit_id'] = $results[0] -> team_visit_id;
				$data['team_visit_name'] = $results[0] -> team_visit_name;
				$data['home_score'] = $results[0] -> home_score;
				$data['visit_score'] = $results[0] -> visit_score;

				//

				$annotations_home = $this -> Torneo_Model -> get_annotations_by_match_id($match_id, $data['team_home_id']);
				$annotations_visit = $this -> Torneo_Model -> get_annotations_by_match_id($match_id, $data['team_visit_id']);

				$data['annotations_home'] = $annotations_home;
				$data['annotations_visit'] = $annotations_visit;

				//print_r($data);
				//$this -> load -> view('score_ajax_view', $data);
				$this -> load -> view('match_user_view', $data);

			} else {

				$data['action'] = "Ver Ficha de Juego";
				$data['message'] = "Identificador del Juego es erroneo.";
				$this -> load -> view('error_view', $data);
				return;

			}

		} else {

			$data['action'] = "Ver Ficha de Juego";
			$data['message'] = "Identificador del Juego no fue proporcionado o es erroneo.";
			$this -> load -> view('error_view', $data);
			return;

		}

	}

	public function testHeadlines(){
		
		
		$this -> load -> model('Torneo_Model');

		$results = $this -> Torneo_Model -> get_tournaments_active();

		$data['tournaments'] = $results;
		
		$this -> load -> view('league_headlines', $data);
	}

	public function listado($tournament_id = FALSE){
		
		if ($tournament_id && is_numeric($tournament_id)){
			
			
			//load view to list teams in the tournament
		}
		
		
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
